IsSquare[n_]:=IntegerQ[Sqrt[n]] (* whether n is square *)

n=9313;(*input odd number *)
d=c=Ceiling[Sqrt[n]];While[!IsSquare[(d^2)-n],Print[d,"^2-",n, " is not a square"];If[d>((n+1)/2),Break[]];d++]
If[d==((n+1)/2),Print[n, " is prime"], Print["Factors: ",d+Sqrt[(d^2)-n],",", d-Sqrt[(d^2)-n]]]

n=47;(*input odd number *)
d=c=Ceiling[Sqrt[n]];While[!IsSquare[(d^2)-n],Print[d,"^2-",n, " is not a square"];If[d>((n+1)/2),Break[]];d++]
If[d==((n+1)/2),Print[n, " is prime"], Print["Factors: ",d+Sqrt[(d^2)-n],",", d-Sqrt[(d^2)-n]]]